package com.zw.admin.server.job;

import com.zw.admin.server.controller.DeviceController;
import com.zw.admin.server.dao.DeviceDao;
import com.zw.admin.server.dao.DeviceHalfHourDao;
import com.zw.admin.server.dto.Device.Iot;
import com.zw.admin.server.model.Device;
import com.zw.admin.server.model.DeviceHalfHour;
import com.zw.admin.server.utils.DeviceUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Array;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class getDataHalfHourJob {

    @Autowired
    private DeviceController deviceController;

    @Autowired
    private DeviceHalfHourDao deviceHalfHourDao;

    public void getDataHalfHour() throws Exception {
        System.out.println("this is getDataHalfHour()");

        //获取温湿度传感器
        List<Iot> temperatureList = deviceController.getTemperatureList();
        for (Iot iot : temperatureList) {
            DeviceHalfHour deviceHF = new DeviceHalfHour();
            DeviceUtils.Iot2DeviceHF(iot, deviceHF);
            deviceHF.setIotType("温湿度传感器");
            deviceHF.setTypeId("0dd1c51132088a48fbf96e623c18c12a0");
            deviceHF.setInsertTime(new Timestamp(new Date().getTime()));
            deviceHalfHourDao.insert(deviceHF);
        }
        List types = new ArrayList<String>();
        //单路智能开关
        types.add("virtual-1598955190846074363");
        List<Iot> oneSwitch = deviceController.getIotList(types);
        for (Iot iot : oneSwitch) {
            DeviceHalfHour deviceHF = new DeviceHalfHour();
            DeviceUtils.Iot2DeviceHF(iot, deviceHF);
            deviceHF.setIotType("单路智能开关");
            deviceHF.setTypeId("07cb95502326de2376339141372ef35c9");
            deviceHF.setInsertTime(new Timestamp(new Date().getTime()));
            deviceHalfHourDao.insert(deviceHF);
        }
        types.remove(0);

        //双路智能开关
        types.add("virtual-1598955217549643631");
        List<Iot> twoSwitch = deviceController.getIotList(types);
        for (Iot iot : twoSwitch) {
            DeviceHalfHour deviceHF = new DeviceHalfHour();
            DeviceUtils.Iot2DeviceHF(iot, deviceHF);
            deviceHF.setIotType("双路智能开关");
            deviceHF.setTypeId("0a0e80c8720c2b3775f1bdf13ca6d4768");
            deviceHF.setInsertTime(new Timestamp(new Date().getTime()));
            deviceHalfHourDao.insert(deviceHF);
        }
        types.remove(0);

        //三路智能开关
        types.add("virtual-1598955239775596035");
        List<Iot> threeSwitch = deviceController.getIotList(types);
        for (Iot iot : threeSwitch) {
            DeviceHalfHour deviceHF = new DeviceHalfHour();
            DeviceUtils.Iot2DeviceHF(iot, deviceHF);
            deviceHF.setIotType("三路智能开关");
            deviceHF.setTypeId("0f3f6e1c72e3a7a13dda206ee857958e4");
            deviceHF.setInsertTime(new Timestamp(new Date().getTime()));
            deviceHalfHourDao.insert(deviceHF);
        }
        types.remove(0);
        //获取智能插座
        List<Iot> socketList = deviceController.getSocketList();
        for (Iot iot : threeSwitch) {
            DeviceHalfHour deviceHF = new DeviceHalfHour();
            DeviceUtils.Iot2DeviceHF(iot, deviceHF);
            deviceHF.setIotType("获取智能插座");
            deviceHF.setTypeId("055358d072d866d6ce58703585e23705e");
            deviceHF.setInsertTime(new Timestamp(new Date().getTime()));
            deviceHalfHourDao.insert(deviceHF);
        }
    }

}
